package com.woniu.goods.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.woniu.goods.domain.Manager;
import com.woniu.goods.util.JDBCUtil;

public class UserDaoImpl implements IUserDao {
	JDBCUtil util = new JDBCUtil();

	@Override
	public Manager selectUManagerByNameAndPass(String name, String pass) {
		Connection conn = null ;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		
		Manager manager = null;
		try {
			conn = util.getConnection();
			String sql = "select * from t_manager where username = ? and password = ?" ;
			pstm = conn.prepareStatement(sql);
			pstm.setObject(1, name);
			pstm.setObject(2, pass);
			
			rs = pstm.executeQuery();
			
			if(rs.next()) {
				manager = new Manager(rs.getInt("mid"), rs.getString("username"), rs.getString("password"), rs.getString("realname"), rs.getString("tel"));
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				util.release(rs, pstm, conn);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return manager;
	}

}
